<?php
///关于标收费信息的统计
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and qtime_h>='$startdate' and  qtime_h<='$enddate'";  
}
$gfileds        = "SUBSTR(qtime_h,1,10 )";
if($MOD=="M"){
    $gfileds    = "SUBSTR(qtime_h,1,7)";    
}   



$rows = $dbselect->GetRows("SELECT 
sum(if(flowty='diyafeiincome',-money,0)) as 押金转利润, sum(if(flowty='diyafeiincome',1,0))as 押金转利润次数,
b.cid,SUBSTR( qtime_h, 1, 10 ) as qtime_h
FROM  `04a_5flow_cid` f  left join 05b_0base b on f.busid =b.bid 
WHERE  `flowty` in ('diyafeiincome') and atnm='cid_yajin' $sfwhere
group by b.cid,SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = $row['qtime_h'];
    $c_b_c  = $row['押金转利润次数'];
    if($c_b_c>0){
        CTLog::G()->pxxDayReal($c_b_c.",cid",$cid,"押金转利润",$row['押金转利润'],$ctime);
    }
}

$rows = $dbselect->GetRows("SELECT 
sum(if(flowty='zhongjiefh',money,0)) as 中介费, sum(if(flowty='zhongjiefh',1,0))as 中介费次数,
b.cid,SUBSTR( qtime_h, 1, 10 ) as qtime_h
FROM  `04a_5flow_cid` f  left join 05b_0base b on f.busid =b.bid 
WHERE  atnm='cid_jinzijin' and atnm2='cid_zjf' and `flowty` in ('zhongjiefh') $sfwhere
group by b.cid,SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = $row['qtime_h'];
    $c_b_zj = $row['中介费次数'];    
    if($c_b_zj>0){
        CTLog::G()->pxxDayReal($c_b_zj.",cid",$cid,"网站_中介费",$row['中介费'],$ctime);
    }
}


//统计体验标利息
$rows = $dbselect->GetRows("SELECT SUM(r.repay_interest_yes) AS lixi,repay_yestime,b.cid FROM  05b_2list_repay r LEFT JOIN 05b_0base b  
		ON b.bid=r.bid WHERE b.flag=5 AND r.repay_yestime>='$startdate' and r.repay_yestime<='$enddate' group by b.cid,repay_yestime ");        

foreach($rows as &$row)
{
    $cid    = $row['cid'];
	$ctime  = $row['repay_yestime'];
	$money = isset($row['lixi']) ? $row['lixi'] : 0;
    //if($money>0){
        CTLog::G()->pxxDayReal("cid",$cid,"体验标利息_实_总",$money,$ctime);
    //}
	//CTLog::G()->pxxDayReal("sid",1,"体验标利息_实_总",$money,$ctime);     //

}
$rows = $dbselect->GetRows("SELECT SUM(r.repay_interest_yes) AS lixi,repay_yestime FROM  05b_2list_repay r LEFT JOIN 05b_0base b  
        ON b.bid=r.bid WHERE b.flag=5 AND r.repay_yestime>='$startdate' and r.repay_yestime<='$enddate' group by repay_yestime ");        

foreach($rows as &$row)
{
    $ctime  = $row['repay_yestime'];
    $money = isset($row['lixi']) ? $row['lixi'] : 0;
    //if($money>0){
        CTLog::G()->pxxDayReal("sid",1,"体验标利息_实_总",$money,$ctime);
    //}
}